/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hvtt.web.payment;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 *
 * @author Administrator
 */
public class onePay {
    private String onepayURL="http://mtf.onepay.vn/onecomm-pay/vpc.op";
   
    private String againLink="http://localhost:8080/Users/c/payment.html";
    private String vpc_Command="pay";
    private String vpc_AccessCode="D67342C2";
    private String vpc_Merchant="ONEPAY";
    private String vpc_MerchTxnRef="TEST_140307745463234201628";
    private String vpc_OrderInfo="";
    private double vpc_Amount=0;
    private String vpc_Locale="vn";
    private String vpc_Currency="VND";
    
    private String vpc_TicketNo="";
    private String vpc_ReturnURL="http://localhost:8080/Users/c/paymentresult.html";
    private String Vpc_SecureHash="";
    private String title="";
    private String vpc_Version="2";
    
    private String vpc_Customer_Email="";
    private String vpc_Customer_Phone="";
    
    private String Error="";
    
    private String find_vpc_OrderInfo()
    {
        return "";
    }
    
   
    public String find_vpc_MerchTxnRef()
    {
         Random rn = new Random();
        String merRef = "TEST_" + System.currentTimeMillis() + rn.nextInt();
        return merRef;
    }
    /**
     * @return the onepayURL
     */
    public String getOnepayURL() {
        return onepayURL;
    }

    /**
     * @param onepayURL the onepayURL to set
     */
    public void setOnepayURL(String onepayURL) {
        this.onepayURL = onepayURL;
    }


    /**
     * @return the againLink
     */
    public String getAgainLink() {
        return againLink;
    }

    /**
     * @param againLink the againLink to set
     */
    public void setAgainLink(String againLink) {
        this.againLink = againLink;
    }

    /**
     * @return the vpc_Command
     */
    public String getVpc_Command() {
        return vpc_Command;
    }

    /**
     * @param vpc_Command the vpc_Command to set
     */
    public void setVpc_Command(String vpc_Command) {
        this.vpc_Command = vpc_Command;
    }

    /**
     * @return the vpc_AccessCode
     */
    public String getVpc_AccessCode() {
        return vpc_AccessCode;
    }

    /**
     * @param vpc_AccessCode the vpc_AccessCode to set
     */
    public void setVpc_AccessCode(String vpc_AccessCode) {
        this.vpc_AccessCode = vpc_AccessCode;
    }

    /**
     * @return the vpc_Merchant
     */
    public String getVpc_Merchant() {
        return vpc_Merchant;
    }

    /**
     * @param vpc_Merchant the vpc_Merchant to set
     */
    public void setVpc_Merchant(String vpc_Merchant) {
        this.vpc_Merchant = vpc_Merchant;
    }

    /**
     * @return the vpc_MerchTxnRef
     */
    public String getVpc_MerchTxnRef() {
        return vpc_MerchTxnRef;
    }

    /**
     * @param vpc_MerchTxnRef the vpc_MerchTxnRef to set
     */
    public void setVpc_MerchTxnRef(String vpc_MerchTxnRef) {
        this.vpc_MerchTxnRef = vpc_MerchTxnRef;
    }

    /**
     * @return the vpc_OrderInfo
     */
    public String getVpc_OrderInfo() {
        return vpc_OrderInfo;
    }

    /**
     * @param vpc_OrderInfo the vpc_OrderInfo to set
     */
    public void setVpc_OrderInfo(String vpc_OrderInfo) {
        this.vpc_OrderInfo = vpc_OrderInfo;
    }

    /**
     * @return the vpc_Amount
     */
    public double getVpc_Amount() {
        return vpc_Amount;
    }

    /**
     * @param vpc_Amount the vpc_Amount to set
     */
    public void setVpc_Amount(double vpc_Amount) {
        this.vpc_Amount = vpc_Amount;
    }

    /**
     * @return the vpc_Locale
     */
    public String getVpc_Locale() {
        return vpc_Locale;
    }

    /**
     * @param vpc_Locale the vpc_Locale to set
     */
    public void setVpc_Locale(String vpc_Locale) {
        this.vpc_Locale = vpc_Locale;
    }

    /**
     * @return the vpc_Currency
     */
    public String getVpc_Currency() {
        return vpc_Currency;
    }

    /**
     * @param vpc_Currency the vpc_Currency to set
     */
    public void setVpc_Currency(String vpc_Currency) {
        this.vpc_Currency = vpc_Currency;
    }

    /**
     * @return the vpc_TicketNo
     */
    public String getVpc_TicketNo() {
        return vpc_TicketNo;
    }

    /**
     * @param vpc_TicketNo the vpc_TicketNo to set
     */
    public void setVpc_TicketNo(String vpc_TicketNo) {
        this.vpc_TicketNo = vpc_TicketNo;
    }

    /**
     * @return the vpc_ReturnURL
     */
    public String getVpc_ReturnURL() {
        return vpc_ReturnURL;
    }

    /**
     * @param vpc_ReturnURL the vpc_ReturnURL to set
     */
    public void setVpc_ReturnURL(String vpc_ReturnURL) {
        this.vpc_ReturnURL = vpc_ReturnURL;
    }

    /**
     * @return the Vpc_SecureHash
     */
    public String getVpc_SecureHash() {
        return Vpc_SecureHash;
    }

    /**
     * @param Vpc_SecureHash the Vpc_SecureHash to set
     */
    public void setVpc_SecureHash(String Vpc_SecureHash) {
        this.Vpc_SecureHash = Vpc_SecureHash;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }
    
    void appendQueryFields(StringBuffer buf, Map fields) {
        List fieldNames = new ArrayList(fields.keySet());
        Iterator itr = fieldNames.iterator();
        while (itr.hasNext()) {
            String fieldName = (String) itr.next();
            String fieldValue = (String) fields.get(fieldName);

            if ((fieldValue != null) && (fieldValue.length() > 0)) {
                buf.append(URLEncoder.encode(fieldName));
                buf.append('=');
                buf.append(URLEncoder.encode(fieldValue));
            }
            if (itr.hasNext()) {
                buf.append('&');
            }

        }

    }
    public String getURLThanhToan()
    {   
      
        
        
        StringBuilder buf = new StringBuilder();
        buf.append(onepayURL).append("?");
        buf.append("vpc_AccessCode=").append(vpc_AccessCode);
        buf.append("&vpc_Command=").append(vpc_Command);
        buf.append("&vpc_OrderInfo=").append(vpc_OrderInfo);
        buf.append("&vpc_ReturnURL=").append(vpc_ReturnURL);
        buf.append("&title=").append(title);
        buf.append("&vpc_Version=").append(getVpc_Version());
        buf.append("&vpc_Locale=").append(vpc_Locale);
        buf.append("&vpc_TicketNo=").append(vpc_TicketNo);
        buf.append("&vpc_Merchant=").append(vpc_Merchant);
        buf.append("&vpc_Amount=").append(vpc_Amount);
        buf.append("&vpc_SecureHash=").append(find_vpc_MerchTxnRef());
        buf.append("&vpc_Currency=").append(vpc_Currency);
        buf.append("&vpc_Locale=").append(vpc_Locale);
        
        
        //appendQueryFields(buf, fields);
        
        return buf.toString();
    }

    /**
     * @return the vpc_Version
     */
    public String getVpc_Version() {
        return vpc_Version;
    }

    /**
     * @param vpc_Version the vpc_Version to set
     */
    public void setVpc_Version(String vpc_Version) {
        this.vpc_Version = vpc_Version;
    }

    /**
     * @return the Error
     */
    public String getError() {
        return Error;
    }

    /**
     * @param Error the Error to set
     */
    public void setError(String Error) {
        this.Error = Error;
    }
}
